/**
 * 
 */
package com.geekteam.masterenglish.provider;

import android.net.Uri;
import android.provider.BaseColumns;
import android.provider.ContactsContract;
import android.text.TextUtils;
//
/**
 * @author MTROL
 *
 */
public class EEContract {
	
	public interface SyncColumns {
        /** Last time this entry was updated or synchronized. */
        String UPDATED = "updated";
    }
	
	public interface LessionColumns{
		String ID = "lessionId";
		String TITLE = "title";
		String TIME_LENGTH = "timeLength";
		String DESCRIPTION = "description";
		String TEXT = "text";
		String LINK_128 = "link128";
		String LINK_320 = "link320";
		String LINKDOWN_128 = "linkdown128";
		String LINKDOWN_320 = "linkdown320";
		String TOTAL_LISTEN = "totalListen";
		String ISFAVORITE = "isFavorite";
		String COVER = "cover";
		String ALBUM_ID = "albumId";
		String ALBUM_NAME = "albumName";
	}
	
	public interface AlbumColumns{
		String ID = "albumId";
		String TITLE = "title";
		String TOTAL_LISTEN = "totalListen";
		String COVER = "cover";
		String BOOK_ID = "bookId";
	}
	
	public static final String CONTENT_AUTHORITY = "com.geekteam.masterenglish";
	public static final Uri BASE_CONTENT_URI = Uri.parse("content://" + CONTENT_AUTHORITY);
	
	public static final String PATH_LESSION = "lessions";
	public static final String PATH_ALBUM = "albums";
	
	public static class Album implements AlbumColumns, BaseColumns{
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_ALBUM).build();
		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.masterenglish.album";
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.masterenglish.album";
		
		public static Uri buildAlbumInBook(String bookId){
			return CONTENT_URI.buildUpon().appendPath("book").appendPath(bookId).build();
		}
		
		public static Uri buildAlbumId(String AlbumId){
			return CONTENT_URI.buildUpon().appendPath(AlbumId).build();
		}
		
		public static String getBookId(Uri uri){
			return uri.getLastPathSegment();
		}
	}
	
	public static class Lession implements LessionColumns, BaseColumns, SyncColumns{
		public static final Uri CONTENT_URI = BASE_CONTENT_URI.buildUpon()
				.appendPath(PATH_LESSION).build();
		public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.masterenglish.lession";
		public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.masterenglish.lession";
		
		public static Uri buildLessionId(String lessionId){
			return CONTENT_URI.buildUpon().appendPath(lessionId).build();
		}
		
		public static Uri buildLesstionAlbum(String Album){
			return CONTENT_URI.buildUpon().appendPath("type").appendPath(Album).build();
		}
		
		public static String getLessionType(Uri uri){
			return uri.getLastPathSegment();
		}
		
		public static String getLessionId(Uri uri){
			return uri.getLastPathSegment();
		}
	}
	
	public static Uri addCallerIsSyncAdapterParameter(Uri uri) {
		return uri
				.buildUpon()
				.appendQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER,
						"true").build();
	}

	public static boolean hasCallerIsSyncAdapterParameter(Uri uri) {
		return TextUtils.equals("true",
				uri.getQueryParameter(ContactsContract.CALLER_IS_SYNCADAPTER));
	}
}
